<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"           
      xmlns:p="http://primefaces.prime.com.tr/ui"
      
      xmlns:ui="http://java.sun.com/jsf/facelets">

    <ui:composition template="/WEB-INF/layout/layout.xhtml">
        <ui:define name="title">Správa článků</ui:define>
        <ui:define name="nadpis">Spravovat články</ui:define>

        <ui:define name="obsah">
            <h:form>
                <h:commandButton value="Software" action="#{ClankyBean.listClankyByKategorie(1,facesContext.viewRoot.viewId)}"/>
                <h:commandButton value="Hardware" action="#{ClankyBean.listClankyByKategorie(2,facesContext.viewRoot.viewId)}"/>
                <h:commandButton value="Hry" action="#{ClankyBean.listClankyByKategorie(3,facesContext.viewRoot.viewId)}"/>
                <h:commandButton value="Site" action="#{ClankyBean.listClankyByKategorie(4,facesContext.viewRoot.viewId)}"/>
            </h:form>

            <h:dataTable id="table1" value="#{ClankyBean.clanky}" var="item">
                <f:facet name="header">
                    <h:outputText value="Nalezené články" />
                </f:facet>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Název" />
                    </f:facet>
                    <h:form>
                        <h:commandLink action="#{ClankyBean.showClanek(item.id)}" value="#{item.nazev}" />
                    </h:form>                    
                </h:column>                
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Návštěvnost" />
                    </f:facet>
                    <h:outputText value="#{item.navstevnost}" />
                </h:column>            
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Odstranit" />
                    </f:facet>
                    <h:form>
                        <h:commandButton action="#{ClankyBean.removeClanek(item.id)}" value="Odstranit"/>
                    </h:form>
                </h:column>            
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Změnit" />
                    </f:facet>
                    <h:form>
                        <h:commandButton action="#{ClankyBean.editClanekRedir(item.id)}" value="Zmenit"/>
                    </h:form>
                </h:column>            
            </h:dataTable>

            <hr />
            <br />
            <h3>Nový článek</h3>

            <h:form> 
                <h:outputLabel value="Nazev: ">
                    <h:inputText value="#{ClankyBean.nazev}" />
                </h:outputLabel> <br />
                <h:outputLabel value="Kategorie: ">
                    <h:selectOneMenu value="#{ClankyBean.kategorie}">
                        <f:selectItem itemValue="1" itemLabel="Software"/>
                        <f:selectItem itemValue="2" itemLabel="Hardware"/>
                        <f:selectItem itemValue="3" itemLabel="Hry"/>
                        <f:selectItem itemValue="4" itemLabel="Site"/>
                    </h:selectOneMenu>
                </h:outputLabel><br /><br />
                <h:outputLabel value="Text: ">
                    <p:editor value="#{ClankyBean.text}" widgetVar="editor" width="500" />
                </h:outputLabel>                 
                <p:commandButton value="Pridat clanek" action="#{ClankyBean.addClanek}" />                                   
            </h:form>

        </ui:define>

        <ui:define name="menu">
            <ui:include src="/WEB-INF/jspf/menu.xhtml" />
        </ui:define>

    </ui:composition>
    
</html>